package com.itheima.chapter12.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
/*
向泛型为Integer的集合，添加String字符串
        java中泛型是假的，只在编译时有效，字节码中无泛型
 */
public class Case1 {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        ArrayList<Integer> list =new ArrayList<>();
        Collections.addAll(list,1,23,56,8,7,56,88);
        //获取list集合对象的字节码文件
        Class<? extends ArrayList> aClass = list.getClass();
        //反射类中add成员方法
        Method addMethod = aClass.getMethod("add", Object.class);
        addMethod.invoke(list,"asd");
        System.out.println(list);
    }
}
